#!/opt/local/bin/perl


#0 <http://purl.obolibrary.org/obo/MP_0010149>
#1 abnormal synaptic dopamine release
#2 <http://purl.obolibrary.org/obo/MP_0010149>
#3 abnormal synaptic dopamine release
#4 1.0
#5 1.0
#6 4.700439718141093
#7 <http://purl.obolibrary.org/obo/MP_0010149>
#8 abnormal synaptic dopamine release

# SimJ_Score	AsymSimJ_Score	LCS_Score

$output = "[";
$i = 0;
while (<STDIN>) {
    if ($i == 0) {
      $i = 1;
    } else {
	    $output .= "{" ;
	    @columns=split("\t");
	#    $output .= @columns[0] . "\n";
	    $output .= "'A': {";
	    $id = @columns[0];
	    $label = @columns[1];

	    # trim the string
	    $label =~ s/^\s+//;
    	$label =~ s/\s+$//;
	    
	    if (!$label) {
	      $label = "null";
	    }

	    # check for single quote at end of line, lop it off if found
	    $output .= "'id':'$id','label':'$label'";
	    $output .= '},';
	    $output .= "'B': {";
	    $id = @columns[2];
	    $label = @columns[3];

	    # trim the string
	    $label =~ s/^\s+//;
    	$label =~ s/\s+$//;
	    
	    if (!$label) {
	      $label = "null";
	    }

	    $output .= "'id':'$id','label':'$label'";
	    $output .= '},';
	    if (@columns[4]) {
	      $simj = @columns[4];
	    } else {
	      $simj = "null";
	    }
	    $output .= "'simJ':$simj,";
	    #$bma_asymj = @columns[5];
	    if (@columns[5]) {
	      $bma_asymj = @columns[5];
	    } else {
	      $bma_asymj = "null";
	    }
	    $output .= "'asymJ':$bma_asymj,";
	     if (@columns[6]) {
	      $lcs_score = @columns[6];
	    } else {
	      $lcs_score = "null";
	    }
	    $output .= "'LCS_Score':$lcs_score,";
	    $output .= "'LCS': {";
	    $id = @columns[7];
	    $label = @columns[8];
	    
	    # trim the string
	    $label =~ s/^\s+//;
    	$label =~ s/\s+$//;
	    
	    if (!$label) {
	      $label = "null";
	    }
	    # check for single quote at end of line, lop it off if found
	    $output .= "'id':'$id','label':'$label'";
	    $output .= '},';

	    chop($output);
	    $output .= "},\n";
	  }
	}
	# remove last comma and carriage return 
	chop($output);
	chop($output);
	$output .= "]";
	
	# replace all pairs single quotes with one quote:
	$output =~ s/''/"/g;
	# replace all single quotes with double quotes:
	$output =~ s/'/"/g;
	print $output;
